﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using DotNetX;

namespace RPGX.Graphics
{
    public class GraphicsSettings
    {
        #region Properties

        public const bool FullScreenDefault = false;
        public const int ScreenWidthDefault = 800;
        public const int ScreenHeightDefault = 600;

        public bool FullScreen
        {
            get { return _fullScreen; }
            set { _fullScreen = value; }
        }
        private bool _fullScreen = GraphicsSettings.FullScreenDefault;

        public int ScreenWidth
        {
            get { return _screenWidth; }
            set { _screenWidth = value; }
        }
        private int _screenWidth = GraphicsSettings.ScreenWidthDefault;

        public int ScreenHeight
        {
            get { return _screenHeight; }
            set { _screenHeight = value; }
        }
        private int _screenHeight = GraphicsSettings.ScreenHeightDefault;

        #endregion

        #region Public Methods

        public bool FromFile(string fileName)
        {
            XDocument doc = XDocument.Load(fileName);

            this.FullScreen = doc.Element("settings").Element("graphics").Element("fullscreen").Value.ToBooleanOrDefault(GraphicsSettings.FullScreenDefault);
            this.ScreenWidth = doc.Element("settings").Element("graphics").Element("screenwidth").Value.ToInt32OrDefault(GraphicsSettings.ScreenWidthDefault);
            this.ScreenHeight = doc.Element("settings").Element("graphics").Element("screenheight").Value.ToInt32OrDefault(GraphicsSettings.ScreenHeightDefault);

            return true;
        }

        #endregion
    }
}
